
package com.eshore.ezone.webservice;

import com.eshore.ezone.utils.MobileConfigs;
import com.eshore.ezone.utils.StringUtils;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.HashMap;

public class ServiceConfigs {
    public static final String SERVER_API_URL = "http://125.88.123.230:8008/ifservice_1.3";
    public static final String SERVER_HUAWEI_URL ="http://androidifs1.189store.com:8080/api";
    
    
    private static final String API_VERSION = "8.0";
    private static ArrayList<BasicNameValuePair> sBaseValuePair;

    static {
        sBaseValuePair = new ArrayList<BasicNameValuePair>();
        sBaseValuePair.add(new BasicNameValuePair("appkey", "2ec45e9835d988ae"));
        sBaseValuePair.add(new BasicNameValuePair("v", API_VERSION));
        sBaseValuePair.add(new BasicNameValuePair("format", "json"));
    }
    
    public static ArrayList<BasicNameValuePair> getLoginUrlValuePairs() {
        ArrayList<BasicNameValuePair> vp =  new ArrayList<BasicNameValuePair>();
        vp.add(new BasicNameValuePair("category", "android"));
        vp.add(new BasicNameValuePair("phone", MobileConfigs.getModel()));
        vp.add(new BasicNameValuePair("method", "getLoginUrl"));
        return vp;
    }
    
    public static ArrayList<BasicNameValuePair> getUserInfoValuePairs(String urlPath) {
        ArrayList<BasicNameValuePair> vp =  new ArrayList<BasicNameValuePair>();
        final String[] uri = urlPath.split("&");
        final int len = uri.length;
        
        for (int i = 0; i < len; i++) {
            String[] params = uri[i].split("=");
            if (params.length == 2) {
                vp.add(new BasicNameValuePair(params[0], params[1]));
            } else {
                vp.add(new BasicNameValuePair(params[0], ""));
            }
        }
        return vp;
    }

    public static ArrayList<BasicNameValuePair> getSyncValuePairs(String appInfo) {
        ArrayList<BasicNameValuePair> vp =  new ArrayList<BasicNameValuePair>();
        vp.addAll(sBaseValuePair);
        vp.add(new BasicNameValuePair("timestamp", "" + System.currentTimeMillis()));
        vp.add(new BasicNameValuePair("appInfos", appInfo));
        vp.add(new BasicNameValuePair("sig", StringUtils.getLoginSig(vp)));
        return vp;
    }
    
    /**
     * 
     * @param parentId 分类父类Id
     * @param showLevel显示层级
     * @return
     */
    public static ArrayList<BasicNameValuePair> getCategoryListPair(String parentId,String showLevel){
        
        ArrayList<BasicNameValuePair> base =  new ArrayList<BasicNameValuePair>();
        base.addAll(sBaseValuePair);
        base.add(new BasicNameValuePair("method", "app.getCategory"));
        base.add(new BasicNameValuePair("startIndex", "0"));
        base.add(new BasicNameValuePair("maxNum", "10"));
        base.add(new BasicNameValuePair("appParentId", parentId));
        base.add(new BasicNameValuePair("showLevel", ""));
        base.add(new BasicNameValuePair("sig",StringUtils.getLoginSig(base)));
        return base;
    }
    
    /**
     * 最新应用排行接口
     * @param rankCycle 按日期排列---- 月，日，周，总 
     * @param level     分类级别 0：获取全部应用   1：cateId为一级分类  2：cateId为二级分类 
     * @param cateId    分类Id
     * @param condition 排序条件
     * @param startIndex起始位置
     * @param maxNum    返回最大个数
     * @return
     */
    public static ArrayList<BasicNameValuePair> getRankListPair(String rankCycle, String level,
            String cateId, String condition, String startIndex, String maxNum) {
        ArrayList<BasicNameValuePair> base =  new ArrayList<BasicNameValuePair>();
        base.addAll(sBaseValuePair);
        base.add(new BasicNameValuePair("method", "app.getAndroidTopList"));
        base.add(new BasicNameValuePair("rankCycle", rankCycle));
        base.add(new BasicNameValuePair("level", level));
        base.add(new BasicNameValuePair("cateId", cateId));
        base.add(new BasicNameValuePair("condition", condition));
        base.add(new BasicNameValuePair("startIndex", startIndex));
        base.add(new BasicNameValuePair("maxNum", maxNum));
        base.add(new BasicNameValuePair("sig", StringUtils.getLoginSig(base)));
        return base;
    }
}
